package me.xplabs.view 
{
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.utils.getQualifiedClassName;
	import me.xplabs.interfaces.IBasePanel;
	import me.xplabs.msg.NotificationName;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	/**
	 * ...
	 * @author xiaohan
	 */
	public class FlagAreaMediator extends Mediator implements IBasePanel  
	{
		private var _container:Sprite;
		private var _isInit:Boolean;
		public static var NAME:String;
		
		//private var _areas:Vector.<Shape>;
		
		private var _areaShape:Shape;
		
		public function FlagAreaMediator(viewComponent:Object=null) 
		{
			NAME = getQualifiedClassName(this);
			super(NAME, viewComponent);
		}
		
		private function init():void
		{
			if (_isInit) return;
			_isInit = true;
			_container = new Sprite();
			
			//_areas = new Vector.<Shape>();
			
			_areaShape = new Shape();
			
			
			
		}
		public function show():void 
		{
			init();
			if (!_container.parent) viewComponent.addChild(_container);
			if (!_areaShape.parent) _container.addChild(_areaShape);
		}
		
		public function hide():void 
		{
			if (_container.parent) _container.parent.removeChild(_container);
			if (_areaShape.parent) _areaShape.parent.removeChild(_areaShape);
		}
		override public function listNotificationInterests():Array 
		{
			return [NotificationName.ROLL_OUT_FLAG,
					NotificationName.ROLL_OVER_FLAG];
		}
		override public function handleNotification(notification:INotification):void 
		{
			show();
			switch(notification.getName())
			{
				case NotificationName.ROLL_OVER_FLAG:
					drawArea(_areaShape.graphics, notification.getBody().pw, notification.getBody().ph);
					_areaShape.x = notification.getBody().x;
					_areaShape.y = notification.getBody().y;
					break;
				case NotificationName.ROLL_OUT_FLAG:
					clearArea(_areaShape.graphics);
					break;
			}
		}
		private function drawArea(g:Graphics, pw:int, ph:int):void
		{
			g.clear();
			g.lineStyle(1, 0x0B4646, 0.8);
			g.beginFill(0x42E1E1, 0.2);
			g.drawEllipse( -pw, -ph, pw * 2, ph * 2);
			g.endFill();
		}
		private function clearArea(g:Graphics):void
		{
			g.clear();
		}
		
		
		public function dispose():void 
		{
			
		}
		
	}

}